package example.simpleservice1;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;

public class BoundServiceActivity extends Activity {
    private static final String TAG = "BoundServiceActivity";

    Context context;
    
    Intent myServiceIntent;
    
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main2);
        
        context = this;
        myServiceIntent = new Intent(context, MyService.class);
        
        
//        ToggleButton serviceToggleButton = (ToggleButton) findViewById(R.id.serviceToggleButton);
        
//        serviceToggleButton.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//			
//			public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//				if(isChecked){
//					
////					startService(myServiceIntent);
//				}else{
////					stopService(myServiceIntent);
//				}
//			}
//		});
        
        Log.i(TAG, "i am started!");
        
    }
    
    public void startService(View v){
    	
    	bindService(myServiceIntent, new ServiceConnection() {
			
    		IBinder service;
    		
			public void onServiceDisconnected(ComponentName name) {
				Log.d(TAG, "onServiceDisconnected");
				service = null;
			}
			
			public void onServiceConnected(ComponentName name, IBinder service) {
				Log.d(TAG, "onServiceConnected");
				this.service = service;
				
			}
		}, Context.BIND_AUTO_CREATE);
    	
    }
    
    @Override
    protected void onDestroy() {
    	super.onDestroy();
    }
    
}